package stackandqueue.stack.application.arithmetic;

/**
 * 栈的应用-四则运算表达式求值-测试方法
 */
public class ArithMain {
    private static ArithUtils arithUtils = new ArithUtils();

    public static void main(String[] args) {
        infixCountTest();
    }

    /**
     * 后缀表达是计算测试
     */
    public static void suffixCountTest() {
        System.out.println("输入后缀表达式，以换行分开各个输入参数，以‘=’结束输入：");
        String[] arguments = arithUtils.suffixInput();
//        String[] arguments = {"9", "3", "1", "-", "3", "*", "+", "10", "2", "/", "+"};
        System.out.println("输入的后缀表达式是：");
        for (String argument : arguments) {
            System.out.print(argument + " ");
        }
        System.out.println();
        Double result = arithUtils.suffixCount(arguments);
        System.out.println("计算结果是：" + result);
    }

    /**
     * 中缀表达式转数组测试
     */
    public static void infix2ArrayTest() {
        String expression = "9+(3-1)*3+10/2";
        String[] result = arithUtils.string2ArrayExpr(expression);
        for (String s : result) {
            System.out.print(s + " ");
        }
    }

    /**
     * 中缀表达式转后缀表达式测试
     */
    public static void infix2suffixTest() {
        String infixExpr = "9+(3-1)*3+10/2";
//        String infixExpr = "9-3+2";
        String[] suffixExpr = arithUtils.infix2suffix(infixExpr);
        System.out.println(suffixExpr);
    }

    /**
     * 中缀表达式计算测试
     */
    public static void infixCountTest() {
//        String infixExpr = "9+(3-1)*3+10/2";
//        String infixExpr = "9-3+1";
        String infixExpr = arithUtils.infixInput();
        System.out.println(arithUtils.infixCount(infixExpr));
    }

}